package com.example.mybaseapp.ui.fragment.recommand

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.example.lib_base.BaseFragment
import com.example.mybaseapp.R
import com.example.mybaseapp.databinding.FragmentPaletteRecommandBinding

class PaletteRecommandFragment: BaseFragment() {
    private var param1: String? = null
    private var param2: String? = null
    private lateinit var binding: FragmentPaletteRecommandBinding
    private lateinit var adapter: PaletteRecommandAdapter
    private val datas= ArrayList<PaletteRecommandBean>()

    companion object {

        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment BlankFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance() =
            PaletteRecommandFragment().apply {
                arguments = Bundle().apply {
//                    putString(ARG_PARAM1, param1)
//                    putString(ARG_PARAM2, param2)
                }
            }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
//            param1 = it.getString(ARG_PARAM1)
//            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate<FragmentPaletteRecommandBinding>(
            inflater,
            R.layout.fragment_palette_recommand,
            container,
            false
        )
        initDatas()
        initRecyclerView()
        return binding.root
    }

    private fun initDatas() {
        datas.apply {
            add(PaletteRecommandBean(R.drawable.ai_light_sensor,requireContext().getString(R.string.ai_light_sensor), true))
//            add(PaletteRecommandBean(R.mipmap.two_light,requireContext().getString(R.string.two_light), false))
//            add(PaletteRecommandBean(R.mipmap.third_light,requireContext().getString(R.string.third_light), false))
//            add(PaletteRecommandBean(R.mipmap.four_light,requireContext().getString(R.string.four_light), false))
        }
    }

    private fun initRecyclerView() {
        binding.txTest.text = "真的测试文案"
        binding.recyclerView.addItemDecoration(HorizontalSpaceItemDecoration(requireContext().resources.getDimensionPixelSize(R.dimen.dp_16)))
        adapter = PaletteRecommandAdapter(datas)
        binding.recyclerView.adapter = adapter
        adapter.notifyItemRangeChanged(0, datas.size)
    }

}